package com.ls.admin.mapper;

import com.ls.pojo.*;
import org.apache.ibatis.annotations.*;


import java.util.List;

@Mapper
public interface AdminMapper {
    //管理员审核用户申请接口
    @Update("UPDATE tb_customer_app_inter SET status=#{status},admin_id=#{adminId} where id=#{id}")
    public void auditInterface(CustomerAppInter customerAppInter);

    //管理员审核注册表
    @Update("UPDATE tb_customer SET dstatus=#{dstatus} where id=#{id}")
    public void auditZhuce(Customer customer);

    //管理员查询自由接口
    @Select("select * from tb_interface where dstatus = 1")
    public List<InterVo> getInterfaceList();

    //管理员查询自由接口返回参数表
    @Select("select * from tb_inter_res where interface_id=${value}")
    public List<InterRes> returnToParameterTable(Integer id);

    //管理员查询自由接口请求参数表
    @Select("select * from tb_inter_req where interface_id=${value}")
    public List<InterReq> requestParameterTable(Integer id);

    //管理员查询第三方接口
    @Select("select * from tb_inter_thirdparty where dstatus = 1")
    public List<InterThirdparty> getThirdpartyList();

    //管理员通过自有id查询自有接口
    @Select("select * from tb_interface where id=${value}")
    public InterVo getInterfaceById(Integer id);

    //管理员对自己接口的删除
    @Update("update tb_interface set dstatus=#{dstatus} where id=#{id}")
    public void deleteLocalInterface(InterVo inter);

    //管理员删除自有接口请求参数
    @Update("update tb_inter_req set dstatus=#{dstatus} where interface_id=#{id}")
    public void deleteInterReq(InterVo inter);

    //管理员自有接口删除返回参数
    @Update("update tb_inter_res set dstatus=#{dstatus} where interface_id=#{id}")
    public void deleteInterRes(InterVo inter);

    //添加自有接口
    @Insert("insert into tb_interface values (null,#{interfaceUrl},#{interfaceUrl},#{returnFormat},#{requestMethod},#{interfaceNotes},#{callerType},0,#{unitPrice},1)")
    public void addInterface(InterVo inter);

    //添加自有接口请求参数
    @Insert("insert into tb_inter_req values (null,#{interfaceId},#{parameterName},#{parameterType},#{parameterDesc},#{required},1)")
    public void addInterReq(InterReq interReq);

    //添加自由接口返回参数
    @Insert("insert into tb_inter_res values (null,#{interfaceId},#{parameterName},#{parameterType},#{parameterDesc},1)")
    public void addInterRes(InterRes interRes);

    //修改自由接口
    @Update("update tb_interface set interface_name=#{interfaceName}, interface_url=#{interfaceUrl}, return_format=#{returnFormat}, request_method=#{requestMethod}, interface_notes=#{interfaceNotes}, caller_type=#{callerType}, review=#{review}, unit_price=#{unitPrice} where id=#{id}")
    public void updateInter(InterVo interVo);

    //修改自由接口请求参数
    @Update("update tb_inter_req set parameter_name=#{parameterName}, parameter_type=#{parameterType}, parameter_desc=#{parameterDesc} where id=#{id}")
    public void updateInterReq(InterReq interReq);

    //修改自由接口返回参数
    @Update("update tb_inter_res set parameter_name=#{parameterName}, parameter_type=#{parameterType}, parameter_desc=#{parameterDesc} where id=#{id}")
    public void updateInterRes(InterRes interRes);

    //管理员对第三方接口的删除
    @Delete("update tb_inter_thirdparty set dstatus=#{dstatus} where id=#{id}")
    public void deleteThirdPartyInterface(InterThirdparty interThirdparty);

    //管理员通过id查询第三方接口
    @Select("select * from tb_inter_thirdparty where id=#{id}")
    public InterThirdparty getThirdpartyById(InterThirdparty interThirdparty);

    //管理员添加第三方接口
    @Insert("INSERT INTO `lingsun2`.`tb_inter_thirdparty` (`thirdparty_name`, `thirdparty_url`, `appkey`, `interface_id`, `i_level`, `dstatus`) VALUES (#{thirdpartyName}, #{thirdpartyUrl}, #{appkey}, #{interfaceId}, #{iLevel}, '1')")
    public int addThirdparty(InterThirdparty interThirdparty);

    //管理员修改第三方接口
    @Update("update tb_inter_thirdparty set thirdparty_name=#{thirdpartyName},thirdparty_url=#{thirdpartyUrl}, appkey=#{appkey}, interface_id=#{interfaceId}, i_level=#{iLevel}, dstatus=#{dstatus} where id=#{id}")
    public void modifyThirdPartyInterface(InterThirdparty interThirdparty);


    @Select("SELECT * FROM tb_customer_app_inter WHERE dstatus = 1 ORDER BY `status` ASC ")
    List<CustomerAppInter> getAppInter();

    @Select("select * from tb_admin where username = #{value}")
    Admin getAdminByName(String adminName);

    @Select("select * from tb_verified_personal ORDER BY `status` ASC ")
    List<VerifiedPersonal> getVeriPers();

    @Select("select * from tb_verified_company ORDER BY `status` ASC")
    List<VerifiedCompany> getVeriComp();

    @Update("update tb_verified_personal set status = 1 where appid=#{value}")
    void updateVerPer(String appid);

    @Update("update tb_customer set user_type = #{typ} where appid=#{appid}")
    void updateCust(@Param("appid") String appid, @Param("typ") int typ);

    @Update("update tb_verified_company set status = 1 where appid=#{value}")
    void updateVerCom(String appid);

    @Select("select * from tb_inter_req where interface_id = #{value}")
    List<InterReq> getInterReq(Integer id);

    @Select("select * from tb_inter_res where interface_id = #{value}")
    List<InterRes> getInterRes(Integer id);

    @Insert("INSERT INTO `lingsun2`.`tb_inter_req` (`interface_id`, `parameter_name`, `parameter_type`, `parameter_desc`, `required`, `dstatus`) VALUES (#{interfaceId}, #{parameterName}, #{parameterType}, #{parameterDesc}, #{required}, '1')")
    int addreq(InterReq interReq);

    @Insert("INSERT INTO `lingsun2`.`tb_inter_res` (`interface_id`, `parameter_name`, `parameter_type`, `parameter_desc`, `dstatus`) VALUES (#{interfaceId}, #{parameterName}, #{parameterType}, #{parameterDesc}, '1')")
    int addres(InterRes interRes);

    @Delete("delete from tb_inter_req where id = #{value}")
    int delreq(Integer id);

    @Delete("delete from tb_inter_res where id = #{value}")
    int delres(Integer id);

    @Insert("INSERT INTO `lingsun2`.`tb_interface` (`interface_name`, `interface_url`, `return_format`, `request_method`, `interface_notes`, `caller_type`, `review`, `unit_price`, `dstatus`, `images`, `interface_example`) VALUES (#{interfaceName}, #{interfaceUrl}, #{returnFormat}, #{requestMethod}, #{interfaceNotes}, #{callerType}, #{review}, #{unitPrice}, '1', #{images}, #{interfaceExample})")
    int addInter(Inter inter);
}
